package com.xxzx.publicprevention.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;

import com.xxzx.publicprevention.pojo.GeoXzqxian;
import com.xxzx.publicprevention.service.GeoXzqxianService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.*;
import java.util.List;

/**
 * (GeoXzqxian)表控制层
 *
 * @author makejava
 * @since 2020-11-10 08:05:15
 */
@RestController
@RequestMapping("/geoXzqxian")
public class GeoXzqxianController {
    /**
     * 服务对象
     */
    @Resource
    private GeoXzqxianService geoXzqxianService;

    @PostMapping("/getAll")
    public List<GeoXzqxian> getAll(GeoXzqxian geoXzqxian) {
        try {
            return geoXzqxianService.queryAll(geoXzqxian);
        }catch (Exception e){
            return null;
        }

    }

    @PostMapping("/test")
    public Object test(String para) {
        try {
            JSONArray EDA10MX_pl=ReadJson("e:/fileContainerQX/testData/EDA10MX_pl.json");
            return EDA10MX_pl;
        }catch (Exception e){
            return null;
        }
    }
    private JSONArray ReadJson(String filePath) {
        String s =readJsonFile(filePath);
        JSONArray jobj = JSON.parseArray(s);
        return jobj;
    }
    private  String readJsonFile(String fileName) {
        String jsonStr = "";
        try {
            File jsonFile = new File(fileName);
            FileReader fileReader = new FileReader(jsonFile);
            Reader reader = new InputStreamReader(new FileInputStream(jsonFile),"utf-8");
            int ch = 0;
            StringBuffer sb = new StringBuffer();
            while ((ch = reader.read()) != -1) {
                sb.append((char) ch);
            }
            fileReader.close();
            reader.close();
            jsonStr = sb.toString();
            return jsonStr;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     * 空间查询——相交
     * @param coords
     * @return
     */
    @GetMapping("/gis_Intersection")
    public List<GeoXzqxian> gis_Intersection(String coords) {
        try {
            return this.geoXzqxianService.gis_Intersection(coords);
        }catch (Exception ee){
            return null;
        }

    }

}
